package com.dj.myapp.slice;

import com.dj.myapp.ResourceTable;
import com.dj.myapp.model.User;
import com.dj.myapp.service.RouterService;
import com.dj.mylibrary.param.UriParam;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.HashMap;

public class MainAbilitySlice extends AbilitySlice {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00202, "MainAbilitySlice");

    Button bt2,bt3,bt4;

    public RouterService mService=new RouterService();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initView();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    private void initView() {
        bt2= (Button) findComponentById(ResourceTable.Id_bt2);
        bt3= (Button) findComponentById(ResourceTable.Id_bt3);
        bt4= (Button) findComponentById(ResourceTable.Id_bt4);

        bt2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

//                Intent intent = new Intent();
//                Operation operation = new Intent.OperationBuilder()
//                        .withAction(Intent.ACTION_QUERY_WEATHER)
//                        .build();
//                intent.setOperation(operation);
//                startAbility(intent);


            }
        });


        bt3.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {


                HashMap<String,Object> data=initParam();

                UriParam param=new UriParam()
                        .setBundleName("com.dj.myapp")
                        .setAbilityName("com.dj.myapp.ThirdAbility");
                mService.toOtherAbility(MainAbilitySlice.this,param,data);

            }
        });

        bt4.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

//                HiLog.info(LABEL, cls.getName()+"|cls.getName()|"+cls.getSimpleName()+"|cls.getSimpleName()");


                HashMap<String,Object> data=initParam();
                mService.toOtherSlice(MainAbilitySlice.this,data,ScanSlice.class);

            }
        });




    }

    private HashMap<String,Object> initParam() {
        HashMap<String,Object> data=new HashMap<>();
        data.put("stringParam","181818");
        data.put("intParam",22222);
        User user=new User("发哥",30);
        data.put("user",user);
        return data;
    }

}
